<?php
declare (strict_types=1);

namespace app\admin\controller;


use app\common\builder\TableBuilder;
use app\common\builder\TableFront;
use think\App;
use think\response\Json;

class ContractBonusPool extends Base
{
    //主键，默认为id
    protected $pk = 'id';

    //主模型
    protected $model = '\app\common\model\ContractBonusPool';

    protected $append = ['type_text'];


    public function index()
    {
        return $this->setTable();
    }

    public function setTable()
    {
        //构建table
        $tableFront = TableFront::getInstance()
            ->addRow(['type' => 'checkbox', 'fixed' => 'left', 'field' => '', 'title' => '全选'])
            ->addRow(['field' => 'id', 'title' => '标识ID', 'width' => 80])
            ->addRow(['field' => 'type_text', 'title' => '分红池类型'])
            ->addRow(['field' => 'total_amount', 'title' => '当前金额', 'modify' => 'add|edit', 'format' => 'input'])
            ->addRow(['field' => 'actual_amount', 'title' => '待结算金额'])
            ->addRow(['field' => 'status', 'title' => '状态', 'templet' => '#status', 'width' => 120, 'unresize' => true])
            ->addRow(['fixed' => 'right', 'align' => 'center', 'toolbar' => '#barDemo', 'title' => '操作', 'width' => 200]);

        return TableBuilder::getInstance()
            ->addColumns($tableFront)
            ->addRightButtons([
                'summary_info' => [
                    'title' => '查看明细',
                    'type' => 'summary_info',
                    'url' => url('summary_info')->build()
                ]
            ])
            ->setSearch($this->setSearch())
            ->addSwitchTool([['name' => 'status', 'pk' => 'id', 'text' => '开启|关闭']])
            ->addJsUrl(['pool'])
            ->fetch('index');
    }

    public function summary_info($id)
    {
        $info = $this->model::find($id);

        $url = url('account/bonus') . '?contract_pool_id='.$id;
        return redirect($url);

    }

    public function setSearch()
    {
        return TableFront::getInstance();
    }

    public function save($param = [], $model = true): Json
    {
        return parent::save($param, $model); // TODO: Change the autogenerated stub
    }

}
